#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    struct node* front;
    int data;
    struct node* next;
}Node;
Node* Createlist();
void  Showlist(Node* head);
void  headinsert(Node* head,int data);
void tailinsert(Node* head,int data);
void deletelist(Node* head,int data);
void  Crearlist(Node* head);
int isempty(Node* head);
int main(){
   Node* head=Createlist();
   headinsert(head,1);
   headinsert(head,23);
   headinsert(head,34);
   headinsert(head,56);
   headinsert(head,67);
   headinsert(head,71);
   headinsert(head,8);
   tailinsert(head,234);
   headinsert(head,23);
   tailinsert(head,2345);
   Showlist(head);
   int num;
    printf("请输入你要删除的元素\n");
    scanf("%d",&num);
    deletelist(head,num);
    printf("删除后");
    Showlist(head);
    return 0;
}
Node* Createlist(){
    Node* head=(Node*)malloc(sizeof(Node));
    head->front=NULL;
    head->next=NULL;
    head->data=0;
    return head;
}
int isempty(Node* head){
    if(head->data==0){
        return 1;
    }
    return 0;
}
void Showlist(Node* head){
    printf("\n链表中的元素个数为%d",head->data);
    Node* pstr=head->next;
    for(;pstr!=NULL;pstr=pstr->next){
        printf(pstr==head->next?"%d":"->%d",pstr->data);
    }
}
void headinsert(Node* head,int data){
    head->data++;
    Node* pnew=(Node*)malloc(sizeof(Node));
    pnew->data=data;
    pnew->next=head->next;
    head->next=pnew;
    pnew->front=head;
    head->next->front=pnew;
}
void tailinsert(Node* head,int data){
    head->data++;
    Node* pstr=head;
    while(pstr->next!=NULL){
        pstr=pstr->next;
    }
    Node* pnew=(Node*)malloc(sizeof(Node));
    pnew->data=data;
    pstr->next=pnew;
    pnew->front=pstr;
    pnew->next=NULL;
}
void deletelist(Node* head,int data){
   if(isempty(head)){
    printf("链表为空,删除失败\n");
   }
    else{
        Node* pstr=head->next;
        int Flags=0;
    for(;pstr->next!=NULL;pstr=pstr->next){
        if(pstr->data==data){
            
            pstr->front->next=pstr->next;
            pstr->next->front=pstr->front;
            
            Flags=1;
           head->data--;
            break;
        }
    }
        if(pstr->data!=data&&Flags==0){
            printf("删除元素不存在,删除失败\n");
        }
        else if(pstr->data==data&&Flags==0){
            pstr->front->next=NULL;
            head->data--;
        }
}
}
void  Crearlist(Node* head){
    head->data=0;
    head->next=NULL;
    head->front=NULL;
}